#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <locale.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/mman.h>
#ifdef HAVE_SYS_FILIO_H
#include <sys/filio.h>
#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef HAVE_PTHREAD_H
#include <pthread.h>
#endif
#include <event.h>
#include "sbase.h"
#include "log.h"
#include "buffer.h"
#include "chunk.h"
#include "timer.h"

#ifndef _CORE_H
#define _CORE_H
#ifdef __cplusplus
extern "C" {
#endif

/* INET */
#ifndef TCP_T
#define TCP_T SOCK_STREAM
#endif
#ifndef UDP_T	
#define UDP_T SOCK_DGRAM 
#endif
#ifndef SOCK_MIX      
#define SOCK_MIX (SOCK_DGRAM | SOCK_STREAM)
#endif
#ifndef DGRAM_SIZE 	
#define DGRAM_SIZE 1024 
#endif
#ifndef BUF_SIZE
#define	BUF_SIZE   1024 * 1024
#endif
#ifndef MAX_CONNECTIONS
#define MAX_CONNECTIONS 	65535
#endif
#ifndef MAX_PACKET_LEN
#define MAX_PACKET_LEN		65535
#endif
#ifndef MAX_THREADS
#define MAX_THREADS		256
#endif
#ifndef MIN_SLEEP_USEC
#define MIN_SLEEP_USEC		1000
#endif 
#ifndef MIN_HEARTBEAT_INTERVAL
#define MIN_HEARTBEAT_INTERVAL  60000000u
#endif
#ifndef MIN_CONN_TIMEOUT
#define MIN_CONN_TIMEOUT	120
#endif
#ifndef  SESSION_MAP_SIZE
#define  SESSION_MAP_SIZE 	1024
#endif
#ifndef	INET_BACKLOG
#define	INET_BACKLOG			65535 
#endif


/* MESSAGE DEFINE*/
#ifndef _TYPEDEF_MESSAGE
#define _TYPEDEF_MESSAGE
/* MESSAGE ACTION ID DEFINE */
#define MESSAGE_QUIT            0x00
#define MESSAGE_NEW_SESSION     0x01
#define MESSAGE_INPUT           0x02
#define MESSAGE_OUTPUT          0x04
#define MESSAGE_PACKET          0x08
#define MESSAGE_DATA          	0x10

typedef struct _MESSAGE{
	int		msg_id;
	int		fd;	
	void		*handler;
	
	void		(*clean)(struct _MESSAGE *);
}MESSAGE;
MESSAGE *message_init();
#define MESSAGE_SIZE	sizeof(MESSAGE)
#endif


/* TYPES PREDEFINE */
struct _SERVICE;
struct _PROCTHREAD;
struct _CONN;
struct _QUEUE;
struct _BUFFER;
#endif
